﻿using System;
using System.Linq;
using Autofac;
using Common.UnitTests;
using Moq;
using NUnit.Framework;
using Wombat.Core;
using Wombat.Core.Gates;
using Wombat.Core.Services;
using Wombat.Data.Model;

namespace Core.UnitTests.Gates
{
    public class FloatingStorageGateUnitTests: UnitTestBase
    {
        [Test]
        public void Ports()
        {
            var storageBaseGate = UnitTestContainer.Resolve<StorageBaseGate>();

            Assert.That(storageBaseGate.Ports.Count(), Is.EqualTo(1));
            Assert.That(storageBaseGate.Ports.First().Name, Is.EqualTo("DataIn"));
            Assert.That(storageBaseGate.Ports.First(), Is.InstanceOf<IObserverPort<ITagValue<double?>>>());
        }

        
        [Test]
        public void InsertData()
        {
            var dbSvc = new Mock<IDataService>();
            dbSvc.Setup(d => d.InsertFloatData(It.Is<FloatData>(fd => fd.TagId == 10 && fd.Value == 10.0d))).Verifiable();
            AddRegistration(b => b.Register(c => dbSvc.Object));

            var tagVal = new Mock<ITagValue<double?>>();
            tagVal.SetupProperty(t => t.TagId, Guid.NewGuid());
            tagVal.SetupProperty(t => t.Value, 10.0d);
            var floatStorageGate = UnitTestContainer.Resolve<FloatStorageGate>();
            floatStorageGate.DataIn.OnNext(tagVal.Object);
            dbSvc.VerifyAll();
        }
    }
}
